﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using Ext.Net;
using Panel = Ext.Net.Panel;

namespace Sharp.Portal.ExtNet.Extend
{
    /// <summary>
    /// List页
    /// </summary>
    public sealed class SharpDataList : Ext.Net.Container
    {
        /// <summary>
        /// List页
        /// </summary>
        public SharpDataList()
        {
            this.Layout = "border";
            DataGrid = new GridPanel()
            {
                Region = Region.Center
            };
            ItemPanel = new Panel()
            {
                Region = Region.East,
                Width = 320,
                Hidden = true,
                Layout = "fit",Border=true,
                Scrollable = ScrollableOption.Vertical
            };

            this.Items.Add(new Panel()
            {
                Region = Region.North
            });
            this.Items.Add(DataGrid);
            this.Items.Add(LogPanel);
            this.Items.Add(ItemPanel);
        }

        /// <summary>
        /// 数据面板
        /// </summary>
        public GridPanel DataGrid { get; set; }

        /// <summary>
        /// 预览面板
        /// </summary>
        public Panel ItemPanel { get; set; }

        /// <summary>
        /// 日志面板
        /// </summary>
        public Panel LogPanel => new Panel()
        {
            Region = Region.South,
            Height = 200,
            Title = "操作日志",
            CollapseMode = CollapseMode.Mini,
            Collapsed = true,
            Collapsible = true
        };
        /// <summary>
        /// 转换为Builder
        /// </summary>
        /// <returns></returns>
        public new Builder ToBuilder()
        {
            return new SharpDataList.Builder(this);
        }

        /// <summary>
        /// Builder
        /// </summary>
        public new class Builder : Builder<SharpDataList, Builder>
        {
            private SharpDataList _component;
            /// <summary>
            /// GridPanel
            /// </summary>
            /// <returns></returns>
            public GridPanel.Builder GridPanel()
            {
                return _component.DataGrid.ToBuilder();
            }
            /// <summary>
            /// GridPanel
            /// </summary>
            /// <param name="component"></param>
            public Builder(SharpDataList component) : base(component)
            {
                _component = component;
            }
            /// <summary>
            /// ItemPanel宽度
            /// </summary>
            /// <param name="width"></param>
            /// <returns></returns>
            public SharpDataList.Builder ItemPanelWidth(int width)
            {
                _component.ItemPanel.Width = new Unit(width);
                return _component.ToBuilder();
            }
        }

    }
}